/*
 * Class ItemOption1
 *
 * Version 1.0
 *
 * Thursday, August 21, 2008
 *
 * Created by Palidino76
 */

package palidino76.rs2.io.packets;

import palidino76.rs2.Engine;



import palidino76.rs2.players.Player;
import palidino76.rs2.util.Misc;

public class ItemOption1 implements Packet {
    /**
     * Handles first item options, excluding things such as eating and drinking.
     * @param p The Player which the frame should be handled for.
     * @param packetId The packet id this belongs to.
     * @param packetSize The amount of bytes being recieved for this packet.
     */
    public void handlePacket(Player p, int packetId, int packetSize) {
        if (p == null || p.stream == null) {
            return;
        }
        int itemSlot = p.stream.readUnsignedWordBigEndianA();
        int interfaceId = p.stream.readUnsignedWord();
        int junk = p.stream.readUnsignedWord();
        int itemId = p.stream.readUnsignedWord();
        if (itemSlot < 0 || itemId < 0) {
            return;
        }
        switch (interfaceId) {
        case 387: // Unequip item.
            if (itemSlot < p.equipment.length && p.equipment[itemSlot] == itemId) {
                if (!Engine.playerItems.addItem(p, p.equipment[itemSlot], p.equipmentN[itemSlot])) {
                    break;
                }
                p.equipment[itemSlot] = -1;
                p.equipmentN[itemSlot] = 0;
                p.frames.setItems(p, 387, 28, 94, p.equipment, p.equipmentN);
                p.playerWeapon.setWeapon();
                p.appearanceUpdateReq = true;
                p.updateReq = true;
                p.calculateEquipmentBonus();
            }
            break;
        default:
            Misc.println("[" + p.username + "] Item option 1: " + interfaceId);
            break;
        }
    }
}
